package main

import (
	"context"
	"fmt"
	"time"
)

type ChainData struct {
	traceId   string
	userId    int64
	sessionId string
}

func (c ChainData) GetTraceId() string {
	return c.traceId
}

func (c ChainData) GetUserId() int64 {
	return c.userId
}

func (c ChainData) GetSessionId() string {
	return c.sessionId
}

var key = "key"

func main() {
	newUUID := "1-2-3-4"
	data := ChainData{
		traceId:   newUUID,
		userId:    1,
		sessionId: "s_123123",
	}
	ctx := context.WithValue(context.Background(), key, data)
	go goPrint(ctx)
	time.Sleep(1 * time.Second)
}

func goPrint(cxt context.Context) {
	value := cxt.Value(key)
	//any类型可以进行类型转换
	data := value.(ChainData)
	fmt.Println(data.GetUserId(), data)
}
